import api from '@/common/api.js'
export default {
	getters:{},
	state:{},
	actions:{
		supportWish({dispatch,commit},ids){
			return new Promise((resolve,reject)=>{
				api.supportWish({group_ids:ids}).then(data=>{
					if(data.is_free===1){
						dispatch('getUserInfo')
						resolve(data)
						return
					}
					const params={
						timeStamp:data.timeStamp+'',
						nonceStr:data.nonceStr,
						package:data.package,
						paySign:data.paySign,
						signType:data.signType,
					}
					uni.requestPayment({
						...params,
						success:(res)=>{
							dispatch('getUserInfo')
							resolve(res)
						},
						fail:(res)=>{
							reject()
							console.log('失败',res)
						}
					})
				}).catch(res=>{
					if(res.code===900000){
						dispatch('getUserInfo')
						resolve(res)
					}else{
						reject()
						uni.showToast({
							icon:'none',
							title: res.msg|| '服务器出错了~~~'
						})
					}
				})
				
			})
		}
	}
}